import moment from 'moment';
import { TimeItem } from "@/pages/park/park-charge/types";

export const getTimeSecond = (timeString: string) => {
  return moment.duration(timeString).asSeconds();
};

export const getTimeMin = (timeString: string) => {
  return moment.duration(timeString).asMinutes();
};

export const MinToDate = (minutes: number) => {
  return moment().startOf('day').add(minutes, 'minutes');
};
// 界面数据编码请求格式
export const encodeTimeItem = (value1: TimeItem) => {
  if (value1.startTime != null && value1.endTime != null) {
    return { startTime: value1.startTime > 0 ? (value1.startTime - 1) * 60 : 0, endTime: (value1.endTime * 60), pricing: value1.pricing * 100 }
  } else {
    return value1
  }
}
// 接口格式 解析成 界面格式
export const decodeTimeItem = (value1: TimeItem) => {
  return { ...value1, startTime: value1.startTime / 60 + 1, endTime: value1.endTime / 60, pricing: value1.pricing / 100 };
}
